/**
 * Author: Shen Yanqiu
 * Date: 2018-02-28
 * Time: 15:02
 *
 */
import modelExtend from 'dva-model-extend';
import {pageModel} from '../../common';
import {message} from 'antd';
import { delay, routerTool } from "utils";

export default modelExtend(pageModel, {
  namespace: 'starRatingRanking',
  state: {},
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        if (location.pathname === routerTool.getPathByName("StarRating")) {
          dispatch({
            type: 'firstLoad',
          });
        }
      });
    },
  },
  effects: {
    * firstLoad ({ payload = {} }, { put, call }) {
      yield put({
        type: 'loadTableList',
        payload: {
          current: 0,
          pageSize: 10,
        },
      });
      yield delay(1000);
    },
    * loadTableList ({ payload = {} }, { put, call }) {
      const data = {
        total: 21,
        list: [
          { id: 1, ranking: 1, name: "张三", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: -1 },
          { id: 2, ranking: 1, name: "王五", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: 11 },
          { id: 3, ranking: 1, name: "李四", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: 2 },
          { id: 4, ranking: 1, name: "网管", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: 6 },
          { id: 5, ranking: 1, name: "卡卡", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: -2 },
          { id: 6, ranking: 1, name: "星星", starlevel: 1, time: "2018-02-28---2018-03-19", huanbi: -1 },
        ],
      };
      yield put({
        type: 'loadSuccess',
        payload: {
          list: data.list,
          pagination: {
            current: payload.current,
            pageSize: payload.pageSize,
            total: data.total,
          },
        },
      });
      yield delay(2000);
    },
  },
  reducers: {},
});
